﻿using System;
using System.Diagnostics;
using System.Windows.Forms;
using pub.CmdUI.UI.Control;
using todo.Plugin;

namespace todo
{
    partial class FrmMain
    {
        private bool _classicUILoaded;

        public Menu MenuTools
        {
            get { return menuTools; }
        }

        private void InitClassicUI()
        {
            if (_classicUILoaded)
            {
                return;
            }
            _classicUILoaded = true;

            LocalizeMenu();
            BindMenuCommands();

            //
            mnViewMenu.Checked = App.Settings.ShowMenu;
            //
            if (Debugger.IsAttached)
            {
                mnDebug.Visible = true;
                sepDebug.Visible = true;
            }

            //
            mnZoomIn.Text += "\tCtrl + ";
            mnZoomOut.Text += "\tCtrl -  ";

            //
            PluginManager.Instance.OnClassicUIInited();

        }

        private void LocalizeMenu()
        {
#if zh
            menuFile.Text = "文件(&F)";
            mnNew.Text = "新建(&N)";
            mnOpen.Text = "打开(&O)...";
            mnSave.Text = "保存(&S)";
            mnSaveAs.Text = "另存为(&A)...";
            mnProperties.Text = "属性(&E)";
            mnExit.Text = "退出(&X)";

            menuEdit.Text = "编辑(&E)";
            mnUndo.Text = "撤销(&U)";
            mnRedo.Text = "重做(&R)";
            mnCut.Text = "剪切(&T)";
            mnCopy.Text = "复制(&C)";
            mnPaste.Text = "粘贴(&P)";
            mnAdd.Text = "添加(&A)";
            mnDelete.Text = "删除(&D)";

            menuView.Text = "查看(&V)";
            mnViewMenu.Text = "菜单(&M)";
            mnViewRibbonUI.Text = "Ribbon界面(&R)";
            menuViewColumns.Text = "列(&C)";
            menuGrid.Text = "网格(&G)";
            mnShowProgress.Text = "进度(&P)";
            mnShowDue.Text = "期限(&D)";
            mnShowDoneItems.Text = "已完成项(&D)";
            mnZoomIn.Text = "放大(&I)";
            mnZoomOut.Text = "缩小(&O)";
            mnZoomReset.Text = "重置(&T)";

            menuTools.Text = "工具(&T)";
            mnDebug.Text = "调试(&D)";
            mnExport.Text = "导出(&E)...";
            mnOptions.Text = "选项(&O)";

            menuHelp.Text = "帮助(&H)";
            mnHelp.Text = "查看帮助(&H)";
            mnAbout.Text = "关于Todo.EXE(&A)";

            //
            mnCollapseAll.Text = "全部收起(&A)";
            mnExpandAll.Text = "全部展开(&E)";
            mnArchive.Text = "归档(&A)";

            //
            mnShowDesc.Text = "描述(&D)";
            mnPrint.Text = "打印(&P)...";
            mnPrintPreview.Text = "打印预览(&V)";

            mnActive.Text = "活动(&A)";

            mnScheduler.Text = "待办调度器";
#else
#endif
        }

        private void BindMenuCommands()
        {
            App.CmdUIManager.Bind(App.Cmds.New, new MenuUI(mnNew));
            App.CmdUIManager.Bind(App.Cmds.Open, new MenuUI(mnOpen));
            App.CmdUIManager.Bind(App.Cmds.Save, new MenuUI(mnSave));
            App.CmdUIManager.Bind(App.Cmds.SaveAs, new MenuUI(mnSaveAs));

            App.CmdUIManager.Bind(App.Cmds.Properties, new MenuUI(mnProperties));

            App.CmdUIManager.Bind(App.Cmds.Exit, new MenuUI(mnExit));

            //
            App.CmdUIManager.Bind(App.Cmds.Undo, new MenuUI(mnUndo));
            App.CmdUIManager.Bind(App.Cmds.Redo, new MenuUI(mnRedo));

            App.CmdUIManager.Bind(App.Cmds.Cut, new MenuUI(mnCut));
            App.CmdUIManager.Bind(App.Cmds.Copy, new MenuUI(mnCopy));
            App.CmdUIManager.Bind(App.Cmds.Paste, new MenuUI(mnPaste));


            App.CmdUIManager.Bind(App.Cmds.AddBefore, new MenuUI(mnAdd));
            App.CmdUIManager.Register(App.Cmds.AddAfter);
            App.CmdUIManager.Register(App.Cmds.AddChild);
            App.CmdUIManager.Bind(App.Cmds.Delete, new MenuUI(mnDelete));

            App.CmdUIManager.Bind(App.Cmds.ZoomIn, new MenuUI(mnZoomIn));
            App.CmdUIManager.Bind(App.Cmds.ZoomOut, new MenuUI(mnZoomOut));
            App.CmdUIManager.Bind(App.Cmds.ZoomReset, new MenuUI(mnZoomReset));

            //
            App.CmdUIManager.Bind(App.Cmds.ShowProgress, new MenuUI(mnShowProgress));
            App.CmdUIManager.Bind(App.Cmds.ShowDesc, new MenuUI(mnShowDesc));
            App.CmdUIManager.Bind(App.Cmds.ShowDue, new MenuUI(mnShowDue));
            App.CmdUIManager.Bind(App.Cmds.ShowDoneItems, new MenuUI(mnShowDoneItems));

            //
            App.CmdUIManager.Bind(App.Cmds.ShowHeader, new MenuUI(mnViewGridHeader));
            App.CmdUIManager.Bind(App.Cmds.ShowTreeLine, new MenuUI(mnViewTreeLine));
            App.CmdUIManager.Bind(App.Cmds.ShowGridLine, new MenuUI(mnViewGridLine));

            //
            App.CmdUIManager.Bind(App.Cmds.Options, new MenuUI(mnOptions));
            App.CmdUIManager.Bind(App.Cmds.Export, new MenuUI(mnExport));
            App.CmdUIManager.Bind(App.Cmds.Debug, new MenuUI(mnDebug));

            //
            App.CmdUIManager.Bind(App.Cmds.Help, new MenuUI(mnHelp));
            App.CmdUIManager.Bind(App.Cmds.About, new MenuUI(mnAbout));

            //
            App.CmdUIManager.Bind(App.Cmds.CollapseAll, new MenuUI(mnCollapseAll));
            App.CmdUIManager.Bind(App.Cmds.ExpandAll, new MenuUI(mnExpandAll));
            App.CmdUIManager.Bind(App.Cmds.Archive, new MenuUI(mnArchive));

            //
            App.CmdUIManager.Bind(App.Cmds.Print, new MenuUI(mnPrint));
            App.CmdUIManager.Bind(App.Cmds.PrintPreview, new MenuUI(mnPrintPreview));
            App.CmdUIManager.Bind(App.Cmds.Active, new MenuUI(mnActive));

            //
            App.CmdUIManager.Bind(App.Cmds.Scheduler, new MenuUI(mnScheduler));
        }


        private void mnViewMenu_Click(object sender, EventArgs e)
        {
            App.Settings.ShowMenu = !App.Settings.ShowMenu;
            mnViewMenu.Checked = App.Settings.ShowMenu;
            if (!App.Settings.ShowMenu)
            {
                var msg = "Menubar is now in auto-hide mode, press ALT key to make it visible";
#if zh
                msg = "菜单进入自动隐藏模式，按Alt键可以使之显示出来";
#endif
                MessageBox.Show(msg, App.Title,
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

    }
}